<template>
    <div class="content">
        <el-card>
            <el-form class="form" label-width="100px">
                <el-row>
                    <el-col :span="4">
                        <el-form-item label="产品信息">
                            <RiskEntryInput
                                :url="'/ledger/fundInfo/list/byUser/like?fundCodeOrName='"
                                @set-entry-data="getEntryslist"
                                :itemKey="'fundProductCode'"
                                :returnDatas="searchParams.codeAndName"
                                class="item"
                                style="display:inline-block"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="产品状态">
                            <el-select v-model="searchParams.fundOptStatus" size="mini" class="item" clearable filterable multiple collapse-tags>
                                <el-option v-for="(value, key) in fundOptStatusPojo" :key="key" :value="key" :label="value"></el-option>
                            </el-select>
                        </el-form-item>        
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="募集方式"> 
                            <el-select 
                                v-model="searchParams.fundType1" 
                                size="mini" 
                                class="item" 
                                clearable 
                                filterable
                                collapse-tags 
                                @change="changeFundType1"
                            >
                                <el-option v-for="(value, key) in FundType1" :key="key" :value="key" :label="value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="产品类型">
                            <el-select 
                                v-model="searchParams.fundType2" size="mini" 
                                class="item" 
                                clearable 
                                filterable 
                                multiple 
                                collapse-tags
                                @focus="focusFundeType2"
                            >
                                <el-option v-for="(value, key) in FundType2" :key="key" :value="key" :label="value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7">
                        <el-form-item label-width="0px" style="margin-left: 50px">
                            <el-button size="mini" type="primary" @click="handleBtn('search')">查询</el-button>
                            <el-button size="mini" @click="handleBtn('loadout')">导出</el-button>
                            <el-button size="mini" @click="handleBtn('layout')">布局设置</el-button>
                            <el-button size="mini" @click="handleBtn('more-search')">{{moreSearch?'收起折叠':'更多查询'}}</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="moreSearch">
                    <el-col :span="4">
                        <el-form-item label="是否指数基金">
                            <el-select v-model="searchParams.isIndexFund" size="mini" class="item" clearable filterable>
                                <el-option key="1" value="1" label="是"></el-option>
                                <el-option key="0" value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="是否现金管理">
                            <el-select v-model="searchParams.isCashManagement" size="mini" class="item" clearable filterable>
                                <el-option key="1" value="1" label="是"></el-option>
                                <el-option key="0" value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="是否QDII">
                            <el-select v-model="searchParams.isQDII" size="mini" class="item" clearable filterable>
                                <el-option key="1" value="1" label="是"></el-option>
                                <el-option key="0" value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="是否FOF">
                            <el-select v-model="searchParams.isFof" size="mini" class="item" clearable filterable>
                                <el-option key="1" value="1" label="是"></el-option>
                                <el-option key="0" value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="是否建仓期">
                            <el-select v-model="searchParams.isBuildPosition" size="mini" class="item" clearable filterable>
                                <el-option key="1" value="1" label="是"></el-option>
                                <el-option key="0" value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="是否定开产品">
                            <el-select v-model="searchParams.isRegularOpen" size="mini" class="item" clearable filterable>
                                <el-option key="1" value="1" label="是"></el-option>
                                <el-option key="0" value="0" label="否"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-card>
        <div class="table">
            <RiskTableP
                ref="risk-table"
                :tableConfig="tableConfig"
                :tableData="tableData"
                :column="actualShowFieldList"
                :paging="paging"
                v-loading="tableLoading"
                :style="({ height: moreSearch ? '100%' : '105%' })"
                @page-change="getTableData(false)"
                :key="tableKey + 'tableKey'"
            >
                <template #closeStartDate="{ row }">
                    <span :style="{ color: row.closedPeriodExpires=='1'?'red':'' }">
                        {{ dateFormat(row.closeStartDate) || '--'}}
                    </span>
                </template>
                <template #closeEndDate="{ row }">
                    <span :style="{ color: row.closedPeriodExpires=='1'?'red':'' }">
                        {{ dateFormat(row.closeEndDate) || '--' }}
                    </span>
                </template>
                <template #operation="{ row }">
                    <RiskIconButton
                        type="primary"
                        icon="el-icon-view"
                        topTitle="查看历史修改记录"
                        @on-click="handleBtnRow('look-history', row)"
                    ></RiskIconButton>
                    <RiskIconButton type="primary" icon="el-icon-edit" topTitle="修改" @on-click="handleBtnRow('update', row)"></RiskIconButton>
                </template>
            </RiskTableP>
        </div>

        <!-- 布局设置 -->
        <RiskTableLayout
            title="产品设置页面布局"
            :visible.sync="layoutDialog"
            :field-list="tableColumns"
            :selected-field-list="selectedFieldList"
            :fixed-field-list="fixedFieldList"
            table-name="TABLE_FUND_INFO_LAYOUT"
            @on-submit="onSubmit"
        />

        <!-- 修改产品信息 -->
        <yh-dialog drag title="修改产品信息" :visible.sync="updateVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="700px">
            <el-form class="form-update" label-width="80px">
                <el-row>
                    <el-form-item label="产品信息">
                        <el-input :value="editInfo.fdProductCode + ' ' + editInfo.fundNameSt" placeholder="选择" size="mini" class="item" disabled>
                        </el-input>
                    </el-form-item>
                </el-row>
                <br />
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="建仓期" class="build-p">
                            <el-input
                                v-model="editInfo.buildPosition"
                                placeholder="请输入整数"
                                size="mini"
                                @input="editInfo.buildPosition = editInfo.buildPosition.replace(/^(0+)|[^\d]+/g, '')"
                            >
                                <!-- <template slot="append">个月</template> -->
                            </el-input>
                            <span class="append">
                                个月
                            </span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="预警线" label-width="120px">
                            <el-input
                                v-model="editInfo.warnLine"
                                placeholder="支持两位小数"
                                size="mini"
                                @input="editInfo.warnLine = editInfo.warnLine.replace(/^(0+)|[^\d]+/g, '')"
                                :disabled="supportEdit"
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="双25%豁免">
                            <el-select v-model="editInfo.double25Exempt" size="mini" class="item" clearable filterable>
                                <el-option v-for="(value, key) in yOrNOptions" :key="value" :value="key" :label="value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="止损线" label-width="120px">
                            <el-input
                                v-model="editInfo.stopLossLine"
                                placeholder="支持两位小数"
                                size="mini"
                                @input="editInfo.stopLossLine = editInfo.stopLossLine.replace(/^(0+)|[^\d]+/g, '')"
                                :disabled="supportEdit"
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="是否指数基金">
                            <el-select v-model="editInfo.isIndexFund" size="mini" class="item" clearable filterable>
                                <el-option key="0" value="0" label="否"></el-option>
                                <el-option key="1" value="1" label="是"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="预警、止损控制类型" label-width="120px">
                            <el-select v-model="editInfo.yjzsxbjjzType" size="mini" class="item" clearable filterable :disabled="supportEdit">
                                <el-option v-for="(value, key) in yjzsxbjjzTypePojo" :key="value" :value="key" :label="value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="是否现金管理">
                            <el-select v-model="editInfo.isCashManagement" size="mini" class="item" clearable filterable>
                                <el-option key="0" value="0" label="否"></el-option>
                                <el-option key="1" value="1" label="是"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="是否定开产品" label-width="120px">
                            <el-select v-model="editInfo.isRegularOpen" size="mini" class="item" clearable filterable @change="changeIsRegularOpen">
                                <el-option key="0" value="0" label="否"></el-option>
                                <el-option key="1" value="1" label="是"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="editInfo.isRegularOpen == '1'">
                    <el-col :span="12">
                        <el-form-item label="封闭期起始日">
                            <el-date-picker 
                                v-model="editInfo.closeStartDate" 
                                size="mini" 
                                class="item" 
                                type="date" 
                                placeholder="选择日期"
                                format="yyyy-MM-dd"
                                value-format="yyyyMMdd"
                            > </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="封闭期" label-width="120px" class="build-p">
                            <el-input 
                                v-model="editInfo.closedPeriod" 
                                size="mini" 
                                @input="editInfo.closedPeriod = editInfo.closedPeriod.replace(/^(0+)|[^\d]+/g, '')"
                            >
                            </el-input>
                            <span class="append">
                                个月
                            </span>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="updateVisible = false">
                    取 消
                </el-button>
                <el-button type="primary" @click="confirm('update')">
                    确 认
                </el-button>
            </div>
        </yh-dialog>

        <UpdateRecord
            type="fund"
            :code="currentFdProductCode"
            @close-custom="historyInfoDialog = false"
            :dialog="historyInfoDialog"
            v-if="historyInfoDialog"
        ></UpdateRecord>
    </div>
</template>
<script lang="ts">
import RiskEntryInput from '@/common/components/risk-entry-input.vue';
import RiskIconButton from '@/common/components/risk-icon-button.vue';
import RiskTableLayout from '@/common/components/risk-table-layout.vue';
import RiskTableP from '@/common/components/risk-table-plus.vue';
import { PageVO, TableConfigVO } from '@/common/vo';
import { downLoadFile } from '@/utils/request';
import { dateFormat } from '@/utils/tools';
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
import * as api from '../api/fund-ledger-manage';
import DictionConstUtil from '../dict';
import RiskInput from './risk-input.vue';
import UpdateRecord from './update-record.vue';
@Component({ name: 'FundInfo', components: { RiskTableP, RiskIconButton, RiskTableLayout, RiskEntryInput, UpdateRecord, RiskInput } })
export default class FundInfo extends Vue {
    dateFormat = dateFormat;
    FundType1 = DictionConstUtil.FundType1;
    FundType2 = {};
    FUNDTYPE2 = DictionConstUtil.FUNDTYPE2;
    fundOptStatusPojo = DictionConstUtil.fundOptStatusPojo;
    yOrNOptions = DictionConstUtil.yOrNOptions;
    yjzsxbjjzTypePojo = DictionConstUtil.yjzsxbjjzTypePojo;
    tableKey: number = -1;
    tableLoading: boolean = true;
    tableConfig: TableConfigVO = {
        rowKey: 'fdProductCode',
        allRowKeys: [], // 所有页数据的key集合
    };
    tableData: any[] = [];
    tableColumns: any = [
        { minWidth: '80px', field: 'fdProductCode', title: '产品代码' },
        { minWidth: '160px', field: 'fundNameSt', title: '产品简称' },
        { minWidth: '100px', field: 'fundOptStatus', title: '产品状态', align: 'center', render: value => this.fundOptStatusPojo[value] },
        { minWidth: '100px', field: 'fundType1', title: '募集方式', align: 'center', render: value => this.FundType1[value] },
        { minWidth: '100px', field: 'fundType2', title: '产品类型', align: 'center', render: value => this.FUNDTYPE2[value] },
        { minWidth: '100px', field: 'setupDate', title: '成立日期', align: 'center', render: value => dateFormat(value) }, // dtCtTime
        { minWidth: '100px', field: 'isBuildPosition', title: '是否建仓期', align: 'center', render: value => this.yOrNOptions[value] }, //
        { minWidth: '100px', field: 'isQDII', title: '是否QDII', align: 'center', render: value => this.yOrNOptions[value] },
        { minWidth: '100px', field: 'isFof', title: '是否FOF', align: 'center', render: value => this.yOrNOptions[value] },
        { minWidth: '100px', field: 'isIndexFund', title: '是否指数基金', align: 'center', render: value => this.yOrNOptions[value] },
        { minWidth: '100px', field: 'isCashManagement', title: '是否现金管理', align: 'center', render: value => this.yOrNOptions[value] },
        {
            minWidth: '100px',
            field: 'buildPosition',
            title: '建仓期',
            align: 'center',
            render: value => (value || value === 0 ? value + '个月' : '--'),
        }, // TODO 建仓期要改成输入类
        { minWidth: '100px', field: 'warnLine', title: '预警线' },
        { minWidth: '100px', field: 'stopLossLine', title: '止损线' },
        { minWidth: '200px', field: 'yjzsxbjjzType', title: '预警、止损控制类型', render: value => DictionConstUtil.yjzsxbjjzTypePojo[value] },
        { minWidth: '100px', field: 'localCustodian', title: '托管行' },
        { minWidth: '100px', field: 'localCustodianName', title: '托管行名称' },
        // { minWidth: '100px', field: 'overAdjustDays', title: '超限调整日期' }, //
        { minWidth: '100px', field: 'oneLevelStrategy', title: '一级策略' },
        { minWidth: '100px', field: 'twoLevelStrategy', title: '二级策略' },
        { minWidth: '100px', field: 'threeLevelStrategy', title: '三级策略' },
        { minWidth: '100px', field: 'investManager', title: '投资经理' },
        { minWidth: '100px', field: 'evaluationMethod', title: '估值方法', render: value => DictionConstUtil.evaluationMethodPojo[value] },
        { minWidth: '100px', field: 'productOptType', title: '运作方式', render: value => DictionConstUtil.productOptTypePojo[value] },
        { minWidth: '100px', field: 'openType', title: '开放期限', render: value => DictionConstUtil.openTypePojo[value] },
        { minWidth: '100px', field: 'riskLevel', title: '风险特征', render: value => DictionConstUtil.riskLevelPojo[value] },
        { minWidth: '100px', field: 'double25Exempt', title: '双25%豁免', render: value => DictionConstUtil.yOrNOptions[value] },
        { minWidth: '100px', field: 'overAdjustDays', title: '超限调整天数' },
        { minWidth: '100px', field: 'isRegularOpen', title: '是否定开产品', align: 'center', render: value => this.yOrNOptions[value] },
        { minWidth: '100px', field: 'closeStartDate', title: '封闭期起始日', align: 'center' }, 
        { minWidth: '100px', field: 'closeEndDate', title: '封闭期截止日', align: 'center' }, 
        { minWidth: '100px', field: 'closedPeriod', title: '封闭期(月)', align: 'center' },
    ];

    paging: PageVO = {
        currentPage: 1,
        pageSize: 25,
        total: 0,
    };

    // 分发配置参数
    searchParams: any = {
        codeAndName: '',
        fundType1: '',
        fundOptStatus: [],
        isIndexFund: '',
        isCashManagement: '',
        isQDII: '',
        isFof: '',
        isRegularOpen: '',
        isBuildPosition: ''
    };

    layoutDialog: boolean = false;
    selectedFieldList: any[] = [];
    showFieldList: any[] = [];
    fixedFieldList: any[] = [
        { minWidth: '80px', field: 'fdProductCode', title: '产品代码' },
        { minWidth: '160px', field: 'fundNameSt', title: '产品简称' },
    ];

    resetNoSelectedFieldList = [
        { minWidth: '200px', field: 'rptAuthManager', title: '关联交易合同授权管理人', align: 'center', render: value => this.yOrNOptions[value] },
        { minWidth: '200px', field: 'rptAuthCustodian', title: '关联交易合同授权托管行', align: 'center', render: value => this.yOrNOptions[value] },
        {
            minWidth: '200px',
            field: 'eptFundsReverseTrans',
            title: '是否豁免产品间同日反向',
            align: 'center',
            render: value => {
                if (value == '0') {
                    return '未豁免';
                } else if (value == '1') {
                    return '豁免';
                } else {
                    return '';
                }
            },
        },
        {
            minWidth: '200px',
            field: 'eptFundReverseTrans',
            title: '是否豁免产品内同日反向',
            align: 'center',
            render: value => {
                if (value == '0') {
                    return '未豁免';
                } else if (value == '1') {
                    return '豁免';
                } else {
                    return '';
                }
            },
        },
    ];
    currentFdProductCode: string = '';
    historyInfoDialog: boolean = false;
    updateVisible: boolean = false; // 更新信息行
    editInfo: any = {};
    selectLoading: boolean = false;
    private issueCodeSelectList: any[] = []; // 发行人代码下拉框数据
    strategyList: any = {};
    moreSearch: boolean = false;

    yjzsxbjjzTypeList = [
        {}
    ]

    get actualShowFieldList() {
        return [
            {
                type: 'checkbox',
                selectedAll: false,
                fixed: 'left',
                align: 'center',
                width: 60,
            },
            ...this.showFieldList,
            {
                title: '操作',
                field: 'operation',
                fixed: 'right',
                width: 120,
                align: 'center',
            },
        ];
    }

    firstVisit: boolean = true; // 首次访问
    supportEdit: boolean = true; // 是否支持编辑预警线、止损控制类型
    @Prop() activeValue: string;
    @Watch('activeValue', { immediate: true })
    async handleActiveValue(newData, oldData) {
        if (newData == 'fund-info' && this.firstVisit) {
            this.tableColumns = this.tableColumns.map(item => {
                return { ...item, id: item.field, content: item.title };
            });
            this.fixedFieldList = this.fixedFieldList.map(item => {
                return { ...item, id: item.field, content: item.title };
            });
            this.resetNoSelectedFieldList = this.resetNoSelectedFieldList.map(item => {
                return { ...item, id: item.field, content: item.title };
            });
            this.firstVisit = false;
            await this.queryLayout();
            this.getTableData(false);
            this.getStrategryList();
        }
    }
    mounted() {
        // window.addEventListener(
        //     'message',
        //     event => {
        //         // debugger;
        //         console.log(event.data);
        //         const data = event.data;
        //         if (data.type == 'task-detail') {
        //             // TODO
        //             alert('进行查询');
        //         }
        //     },
        //     false
        // );
    }

    /**
     * 各级策略下拉框值
     */
    getStrategryList() {
        api.strategryList('1090').then((res: any) => {
            this.strategyList['first'] = res || {};
        });

        api.strategryList('1091').then((res: any) => {
            this.strategyList['second'] = res || {};
        });

        api.strategryList('1098').then((res: any) => {
            this.strategyList['third'] = res || {};
        });
    }

    // 获取页面布局信息
    async queryLayout() {
        let resList: any = await new Promise((resolve, reject) => {
            this.$axios('/tableLayout/query/TABLE_FUND_INFO_LAYOUT')
                .then((res: any) => {
                    resolve(res);
                })
                .catch(err => {
                    reject(err);
                });
        });

        if (resList) {
            this.selectedFieldList = [];

            const list = JSON.parse(resList) || [];
            list.forEach(item => {
                let obj = this.tableColumns.find(ele => ele.content === item.content); //
                if (obj) {
                    this.selectedFieldList.push(obj);
                }
            });

            this.showFieldList = this.fixedFieldList.concat(this.selectedFieldList);
            this.tableKey++;
        } else {
            const keys = this.resetNoSelectedFieldList.map(item => item['id']);
            this.showFieldList = this.tableColumns.filter(item => !keys.includes(item.id));
            const fixKeys = this.fixedFieldList.map(item => item.id);
            this.selectedFieldList = this.showFieldList.filter(item => !fixKeys.includes(item.id));
            this.tableKey++;
        }
    }

    /**
     * 表格数据
     */
    getTableData(reset: boolean) {
        // code?: string
        // code && (this.searchParams.codeAndName = code);
        this.tableLoading = true;
        return new Promise((resolve, reject) => {
            api.productInfoList({ ...this.searchParams, paging: this.paging })
                .then((res: any) => {
                    this.tableData = res?.list || [];

                    this.paging.total = res?.total || 0;

                    reset && this.resetCheckRowKeys();
                    resolve(res);
                })
                .catch((err: any) => {
                    const res = {
                        list: [{ fundNameSt: '测试数据', setupDate: 20231213, fdProductCode: '121', stopLossLine: '1234567890.123456789012', isRegularOpen: '1', closeStartDate: 20220612, closeEndDate: 20221212, closedPeriod: 6, closedPeriodExpires: '1' }],
                        total: 1,
                    };
                    this.tableData = res.list || [];
                    this.paging.total = res.total;

                    reject(err);
                })
                .finally(() => {
                    this.tableLoading = false;
                });
        });
    }

    // 产品代码
    getEntryslist(val: any) {
        this.searchParams.codeAndName = val;
    }

    /**
     * 按钮点击
     */
    async handleBtn(type: string) {
        if (type == 'search') {
            this.paging.currentPage = 1;
            this.getTableData(true);
        } else if (type == 'loadout') {
            const checkRowKeys = (this.$refs as any)['risk-table'].checkRowKeys || [];
            await downLoadFile({
                url: '/ledger/product/export',
                method: 'post',
                data: checkRowKeys.length ? { fdProductCodes: checkRowKeys } : this.searchParams,
            });
            this.resetCheckRowKeys();
        } else if (type == 'layout') {
            this.layoutDialog = true;
        } else if (type == 'more-search') {
            this.moreSearch = !this.moreSearch;
        }
    }

    /**
     * 重置勾选
     */
    resetCheckRowKeys() {
        this.$nextTick(() => {
            (this.$refs['risk-table'] as any).resetCheckRowKeys();
        });
    }
    /**
     * 确认按钮点击
     */
    confirm(type: string) {
        if (type == 'update') {
            console.log('====', this.editInfo.closeStartDate, typeof this.editInfo.closeStartDate)
            if (this.editInfo.isRegularOpen == '1' && (this.editInfo.closeStartDate == '' || this.editInfo.closeStartDate == null)) {
                this.yh_message_warn('封闭期起始日不可为空！');
                return
            }
            if (this.editInfo.isRegularOpen == '1' && this.editInfo.closedPeriod == '') {
                this.yh_message_warn('封闭期(月)不可为空！');
                return
            }
            let editInfo = JSON.parse(JSON.stringify(this.editInfo))
            if (this.editInfo.isRegularOpen == '0' || this.editInfo.isRegularOpen == '') {
                editInfo.closeStartDate = undefined;
                editInfo.closedPeriod = undefined;
                editInfo.closeEndDate = undefined;
            } else if (this.editInfo.isRegularOpen == '1') {
                editInfo.closeEndDate = undefined;
            }
            api.productUpdate(editInfo)
                .then((res: any) => {
                    this.yh_message_success('修改成功');
                    this.getTableData(true);
                    this.editInfo = {};
                })
                .finally(() => {
                    this.updateVisible = false;
                });
        }
    }

    /**
     * 布局设置
     */
    onSubmit() {
        this.queryLayout();
    }

    /**
     * 表格行按钮处理
     */
    async handleBtnRow(type: string, row: any) {
        if (type == 'look-history') {
            this.historyInfoDialog = true;
            this.currentFdProductCode = row.fdProductCode;
        } else if (type == 'update') {
            this.updateVisible = true;
            await this.getSystemParam();
            await this.getCurrentRow(row.fdProductCode);
        }
    }

    /**
     * 获取当前行数据进行修改
     */
    getCurrentRow(code: string) {
        return new Promise((resolve, reject) => {
            api.productDetail({ fundCode: code })
                .then((res: any) => {
                    let editInfo = JSON.parse(JSON.stringify(res))
                    console.log('edit---', editInfo, res.closeStartDate)
                    if (res.closeStartDate) {
                        editInfo['closeStartDate'] = String(res.closeStartDate);
                    } else {
                        editInfo['closeStartDate'] = String(res.setupDate)
                    }
                    if (res.closedPeriod) {
                        editInfo['closedPeriod'] = res.closedPeriod;
                    } else {
                        editInfo['closedPeriod'] = 12;
                    }
                    this.editInfo = editInfo;
                    resolve(res);
                })
                .catch(err => {
                    reject(err);
                });
        });
    }
    getSystemParam() {
        this.$axios
            .get('/systemParam/getKey?key=C_IS_SYS_INTEGRATED_SERVICE')
            .then((res: any) => {
                this.supportEdit = res.paramValue == '1';
            });
    }

    /**
     * 获取发行人代码下拉框数据
     */
    getIssueCodeList(e: string) {
        this.selectLoading = true;
        this.$axios
            .post('/dict/issue/select', {
                dictKey: e,
                dictKeyName: e,
            })
            .then((res: any) => {
                this.issueCodeSelectList = res || [];
                this.selectLoading = false;
            });
    }
    // 募集方式变动
    changeFundType1(value) {
        this.searchParams.fundType2 = [];
        if (value == '') {
            this.FundType2 = {};
        } else if (value == 'D') {
            this.FundType2 = DictionConstUtil.FundType3;
        } else if (['A', 'B'].includes(value)) {
            this.FundType2 = DictionConstUtil.FundType2;
        }
    }
    // 产品类型变动
    focusFundeType2() {
        if (this.searchParams.fundType1 == '') {
            this.yh_message_warn('先选择募集方式!')
            return
        }
    }
    changeIsRegularOpen(value) {
        if (value == '1') {
            this.editInfo['closeStartDate'] = String(this.editInfo['setupDate']);
            this.editInfo['closedPeriod'] = 12;
        }
    }
}
</script>
<style lang="scss" scoped>
.content {
    height: 100%;
    background-color: #fff;
    .form {
    //     display: grid;
    //     grid-template-columns: repeat(4, 1fr) 278px;
    //     .el-form-item {
    //         margin-bottom: 0px;
    //     }
    //     .item {
    //         width: 70%;
    //         /deep/ .el-select {
    //             width: 100%;
    //         }
    //     }
        // /deep/ .el-form-item {
        //     margin-bottom: 5px
        // }
    }
    .table {
        padding: 10px;
        margin-top: 10px;
        height: calc(100% - 140px);
        background-color: #fff;
    }

    .form-search {
        display: grid;
        grid-template-columns: 1fr 1fr;
        .el-form-item {
            margin-bottom: 10px;
        }
        .item {
            width: 100%;
        }
    }
    .form-update {
        // display: grid;
        // grid-template-columns: 1fr 1fr;
        // gap: 0px 80px;
        // .el-form-item {
        //     margin-bottom: 6px;
        // }
        // .item {
        //     width: 100%;
        // }
        // /deep/ .el-select {
        //     width: 100%;
        // }
        // /deep/ .el-input__inner {
        //     border-radius: 0% !important;
        // }
        .build-p {
            .el-input {
                width: calc(100% - 60px);
            }
        }
        .build-p .el-input-group__prepend {
            background-color: #fff;
        }
        // .input-with-select .el-input-group__prepend {
        //     background-color: #fff;
        // }
    }

    .dialog-footer {
        text-align: right;
        margin-right: 10px;
    }
}
.append {
    display: inline-block;
    padding: 0 6px;
    height: 28px;
    line-height: 26px;
    border: 1px solid #c5c6c7;
}
/deep/ .el-select__tags {
    flex-wrap: nowrap;
}

/deep/ span.el-tag.el-tag--info.el-tag--mini.el-tag--light {
    display: flex;
    align-items: center;
    width: 74%;
    max-width: fit-content;
    padding: 0px;
    margin: 2px 0 2px 2px;
    .el-select__tags-text {
        display: inline-block;
        font-size: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/deep/ .el-select {
    .el-tag__close.el-icon-close {
        right: 1px;
    }
}
/deep/ .el-form-item {
    margin-bottom: 0px
}
</style>
